package com.gary.spring;

import com.gary.spring.bean.Config;
import com.gary.spring.process.MyComponentScanPostProcessor;
import org.springframework.beans.factory.support.*;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author peng_rui
 * @date 2022/6/23
 */
public class BeanFactoryMain {
    public static void main(String[] args) throws IOException {
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("config", Config.class);

        //ConfigurationPostProcess 处理@Bean @ComponentScan @Import @ImportScan
        //@ComponentScan 需要与 Component 配合使用，否则ConfigurationClassPostProcessor无法注入到容器
//        context.registerBean(ConfigurationClassPostProcessor.class);

        context.registerBean(MyComponentScanPostProcessor.class);

        context.refresh();

        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
    }
}
